// pages/speak/dospeak/dospeak.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    startnum: [{
        id: 0,
        url1: '/pages/imgs/img/start.png',
        url2: '/pages/imgs/img/start2.png'
      },
      {
        id: 1,
        url1: '/pages/imgs/img/start.png',
        url2: '/pages/imgs/img/start2.png'
      },
      {
        id: 2,
        url1: '/pages/imgs/img/start.png',
        url2: '/pages/imgs/img/start2.png'
      },
      {
        id: 3,
        url1: '/pages/imgs/img/start.png',
        url2: '/pages/imgs/img/start2.png'
      },
      {
        id: 4,
        url1: '/pages/imgs/img/start.png',
        url2: '/pages/imgs/img/start2.png'
      }
    ],
    startindex: -1,
    oid:'',
    gid:'',
    uid:'',
    img:'',
    value:'',
  },
  // 评价点星星
  clickstart: function(e) {
    // console.log(e.currentTarget.dataset.idx)
    let index = parseInt(e.currentTarget.dataset.idx);
    console.log(index)
    this.setData({
      startindex: index
    })
  },
  //获取评论内容
  inputvalue:function(e){
    console.log(e.detail.value)                                        
    this.setData({
      value:e.detail.value
    })
  },
  // 提交评价
  submit() {
    let that = this
    console.log(that.data.value)
    if (that.data.value==''|| that.data.startindex+1<1){
         wx.showToast({
           title: '请打星和评价',
         })
    }else{
      wx.request({
        url: app.globalData.api + "setcomment",
        data: {
          oid: that.data.oid,
          uid: that.data.uid,
          gid: that.data.gid,
          content: that.data.value,
          star: that.data.startindex+1
        },
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        method:'POST',
        success: function (res) {
          console.log(res)
          if(res.data.code==0){
            wx.showToast({
              title: '评论成功',
            })
            setTimeout(function () {
              wx.redirectTo({
                url: '/pages/order/order',
              })
            }, 2000)
          }else{
            wx.showToast({
              title: res.data.msg,
            })
          }
     
        },
      })
    }
    
  },
  // 上传图片
  // upimg() {
  //   wx.chooseImage({
  //     count: 1,
  //     sizeType: ['original', 'compressed'],
  //     sourceType: ['album', 'camera'],
  //     success(res) {
  //       // tempFilePath可以作为img标签的src属性显示图片
  //       const tempFilePaths = res.tempFilePaths
  //     }
  //   })
  // },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    console.log(options)
   
    wx.getStorage({
      key: 'userinfo',
      success: function(res) {
        that.setData({
          uid:res.data.id
        })
      },
    })
    that.setData({
      oid: options.oid,
      gid: options.gid,
      img: options.img
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})